<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>编辑印章刻制</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>印章刻制信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>申请类型</label>
                        <div class="layui-input-block">
                            <select id="shenlei" name="shenlei" lay-filter="shenlei" ></select>
                            <p class="error" id="shenlei_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>是否备案</label>
                        <div class="layui-input-block">
                            <select id="isbei" name="isbei" lay-filter="isbei" >
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                            <p class="error" id="isbei_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=seal_zhi','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=seal_zhi','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>印章类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="yinlei">

                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>印章形状</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="yinxing">

                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">刻章日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="kedt" id="kedt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">收回日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="shoudt" id="shoudt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">印章启用函</label>
                        <div class="layui-input-block">
                            <select id="yinhan" name="yinhan" lay-filter="yinhan" ></select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>印章内容</label>
                        <div class="layui-input-block">
                            <input type="text" name="yinnei" id="yinnei" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea" style="line-height: 30px!important;"><text>*</text>申请事由(使用范围)</label>
                        <div class="layui-input-block">
                            <textarea id="shenshi" name="shenshi" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">印章保管人</label>
                        <div class="layui-input-block">
                            <input type="text" name="baoer" id="baoer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            yinnei: {required: true},
            shenshi: {required: true},
        },
        messages:{
            yinnei: {required: "请输入"},
            shenshi: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_seal_zhi_edit,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#isbei").val(data.isbei);
                $("#kedt").val(data.kedt);
                $("#shoudt").val(data.shoudt);
                $("#yinnei").val(data.yinnei);
                $("#shenshi").val(data.shenshi);
                $("#baoer").val(data.baoer);
                $("#explain").val(data.explain);

                var engininfo = res.data.engininfo;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);
                }

                var shenlei_str = '<option value="">请选择</option>';
                var shenlei = res.data.shenlei;
                for (var key in shenlei){
                    if(shenlei[key] == data.shenlei){
                        shenlei_str += '<option value="'+shenlei[key]+'" selected>'+shenlei[key]+'</option>';
                    }else{
                        shenlei_str += '<option value="'+shenlei[key]+'">'+shenlei[key]+'</option>';
                    }
                }
                $("#shenlei").html(shenlei_str);

                var yinhan_str = '<option value="">请选择</option>';
                var yinhan = res.data.yinhan;
                for (var key in yinhan){
                    if(yinhan[key] == data.yinhan){
                        yinhan_str += '<option value="'+yinhan[key]+'" selected>'+yinhan[key]+'</option>';
                    }else{
                        yinhan_str += '<option value="'+yinhan[key]+'">'+yinhan[key]+'</option>';
                    }
                }
                $("#yinhan").html(yinhan_str);


                var yinlei_str = '';
                var yinlei = res.data.yinlei;
                for (var key in yinlei){
                    if(in_array(yinlei[key],data.yinleiArr)){
                        yinlei_str += '<input type="checkbox" name="yinlei" lay-filter="yinlei" value="'+yinlei[key]+'" title="'+yinlei[key]+'" lay-skin="primary" checked>';
                    }else{
                        yinlei_str += '<input type="checkbox" name="yinlei" lay-filter="yinlei" value="'+yinlei[key]+'" title="'+yinlei[key]+'" lay-skin="primary" >';
                    }
                }
                $("#yinlei").html(yinlei_str);

                var yinxing_str = '';
                var yinxing = res.data.yinxing;
                for (var key in yinxing){
                    if(in_array(yinxing[key],data.yinxingArr)){
                        yinxing_str += '<input type="checkbox" name="yinxing" lay-filter="yinxing" value="'+yinxing[key]+'" title="'+yinxing[key]+'" lay-skin="primary" checked>';
                    }else{
                        yinxing_str += '<input type="checkbox" name="yinxing" lay-filter="yinxing" value="'+yinxing[key]+'" title="'+yinxing[key]+'" lay-skin="primary" >';
                    }
                }
                $("#yinxing").html(yinxing_str);


                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('select(shenlei)', function(data){
            if(data.value == ''){
                $('#shenlei_error').show().text('请选择');
                $('#shenlei_error').parent().find('input').addClass('select_error');
            }else{
                $('#shenlei_error').hide();
                $('#shenlei_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(isbei)', function(data){
            if(data.value == ''){
                $('#isbei_error').show().text('请选择');
                $('#isbei_error').parent().find('input').addClass('select_error');
            }else{
                $('#isbei_error').hide();
                $('#isbei_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            data.field.enginid = get_choose_val('enginid');
            var validRes = $("#commentForm").valid();

            if(data.field.shenlei == ''){
                $('#shenlei_error').show().text('请选择');
                $('#shenlei_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#shenlei_error').hide();
                $('#shenlei_error').parent().find('input').removeClass('select_error');
            }

            if(data.field.isbei == ''){
                $('#isbei_error').show().text('请选择');
                $('#isbei_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#isbei_error').hide();
                $('#isbei_error').parent().find('input').removeClass('select_error');
            }

            formValid('enginid');
            if(data.field.enginid == undefined || !data.field.enginid){
                validRes = false;
            }

            if(!validRes){return false;}


            data.field.yinlei = get_checkbox_value('yinlei');
            data.field.yinxing = get_checkbox_value('yinxing');


            data = parseMoney(data);
            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_seal_zhi_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



    function get_checkbox_value(dom) {
        var obj = document.getElementsByName(dom);
        var str = '';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked){
                if(str){
                    str += ','+obj[i].value
                }else{
                    str += obj[i].value
                }
            }
        }
        return str;
    }
</script>
</body>
</html>
